﻿package UIComponents
{
	import Classes.GameUtils.GU_Color;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	/** 
	 * @author thy
	 * @version 1.0.0 
	 * 创建时间：May 9, 2012 2:52:03 PM 
	 */ 
	public class DayRewardUI extends Sprite
	{
		private var lqBtn:DisplayObject;
		private var addFensiBtn:DisplayObject;
		
		public function DayRewardUI()
		{
			init();
		}
		
		private function init():void
		{
			this.lqBtn=this.getChildByName("acceptRewardBtn");
			this.addFensiBtn=this.getChildByName("addFensi");
			
			this.lqBtn.addEventListener(MouseEvent.CLICK,lqFun);
			this.addFensiBtn.addEventListener(MouseEvent.CLICK,addFensiFun);
		}
		
		
		private function lqFun(e:MouseEvent):void
		{
			this.dispatchEvent(new PanelEvent(PanelEvent.CUSTOMCALLBACK,true));
		}
		
		private function addFensiFun(e:MouseEvent):void
		{
			this.dispatchEvent(new PanelEvent(PanelEvent.ADDJS,true));
		}
		
		private function getDisplayByIndex(index:int):DisplayObjectContainer
		{
			if(index<0 || index>5)throw new Error("索引出错");
			return (this.getChildByName("reward"+index)) as DisplayObjectContainer;
		}
		
		//再加入一个参数 来判断是否已经成为粉丝
		public function setRewardData(arr:Array,day:int,isFenSi:Boolean):void
		{
			if(isFenSi)
			{
				this.addFensiBtn.visible=false;
			}else{
				this.addFensiBtn.visible=true;
			}
			
			for(var i:int=0;i<5;i++)
			{
				var obj:Object=arr[i];
				if(null==obj)
				{
					this.getChildByName("reward"+i).visible=false;
				}else{
					var dc:DisplayObjectContainer=this.getDisplayByIndex(i);
					var icon:IconContainer=dc.getChildByName("icon") as IconContainer;
					if(int(obj.itemNum)<1)dc.getChildByName("num").visible=false;
					var num:TextField=(dc.getChildByName("num") as DisplayObjectContainer).getChildByName("txt_num") as TextField;
					var bg:DisplayObject=dc.getChildByName("bg");
					var iic:DisplayObject=obj.icon;
					iic.width=79;
					iic.height=79;
					icon.addPic(iic,obj.displayViewIconName);
					num.text=obj.itemNum;
					
					if(day<(i+1))
					{
						if(i!=4)
						{
							bg.filters=null;
						}
						if(!isFenSi && i==4)
						{
							bg.filters=null;
						}
					}
//					if(day>=(i+1))
//					{
//						//bg,颜色值
//						bg.filters=[GU_Color.instance.changeSX(10),GU_Color.instance.changeLD(6),GU_Color.instance.changeBHD(30),GU_Color.instance.changeDBD(70)];;
//					}else{
//						//颜色值
//						bg.filters=null;
//					}
//					if(isFenSi && i==4)
//					{
//						//粉丝  亮起来
//						bg.filters=[GU_Color.instance.changeSX(10),GU_Color.instance.changeLD(6),GU_Color.instance.changeBHD(30),GU_Color.instance.changeDBD(70)];;
//					}else if(!isFenSi && i==4){
//						//不是粉丝 暗下去
//						bg.filters=null;
//					}
				}
					
			}

		}
	}
}
